﻿using System.Text;
using System.Xml;

namespace AllNations.Framework
{
    public class VideoIntegrationConfiguration
    {
        public string YouTubeKeyword { get; set; }
        public string YouTubeAuthorName { get; set; }

        internal void Deserialize(string sSettings)
        {
            if (!string.IsNullOrEmpty(sSettings))
            {
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(sSettings);
                XmlElement elem = doc.DocumentElement;
                var nodePageSize = elem.SelectSingleNode("YouTubeKeyword");
                if (nodePageSize != null)
                    YouTubeKeyword = nodePageSize.InnerText;
                else
                    YouTubeKeyword = string.Empty;
                var nodeAuthorName = elem.SelectSingleNode("YouTubeAuthorName");
                if (nodeAuthorName != null)
                    YouTubeAuthorName = nodeAuthorName.InnerText;
                else
                    YouTubeAuthorName = string.Empty;
            }
            else
            {
                // default settings
                YouTubeKeyword = string.Empty;
                YouTubeAuthorName = string.Empty;
            }
        }

        internal string Serialize()
        {
            StringBuilder sb = new StringBuilder();
            XmlWriter writer = XmlWriter.Create(sb);
            writer.WriteStartDocument();
            writer.WriteStartElement("VideoIntegrationSettings");
            writer.WriteElementString("YouTubeKeyword", YouTubeKeyword);
            writer.WriteElementString("YouTubeAuthorName", YouTubeAuthorName);
            writer.WriteEndElement();
            writer.WriteEndDocument();
            writer.Flush();
            return sb.ToString();
        }
    }
}